package com.waikuai.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.waikuai.shop.entity.Product;
import com.waikuai.shop.vo.ProductSimpleVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    IPage<ProductSimpleVO> selectProductPageWithCategory(
            Page<ProductSimpleVO> page,
            @Param("categoryId") Long categoryId,
            @Param("keyword") String keyword,
            @Param("status") Integer status,
            @Param("isFeatured") Integer isFeatured,
            @Param("orderBy") String orderBy,
            @Param("orderType") String orderType);

    List<Product> selectHotProducts(@Param("limit") Integer limit);

    List<Product> selectNewProducts(@Param("limit") Integer limit);

    List<Product> selectFeaturedProducts(@Param("limit") Integer limit);

    List<Product> selectProductsByCategoryId(
            @Param("categoryId") Long categoryId,
            @Param("limit") Integer limit);

    List<Product> searchProducts(
            @Param("keyword") String keyword,
            @Param("limit") Integer limit);

    int incrementViewCount(@Param("productId") Long productId);

    int incrementSalesCount(
            @Param("productId") Long productId,
            @Param("quantity") Integer quantity);

    int updateStock(
            @Param("productId") Long productId,
            @Param("quantity") Integer quantity);

    int updateSalesCount(
            @Param("productId") Long productId,
            @Param("quantity") Integer quantity);
}
